Open to remote roles
Copied to clipboard ✓
Command Reference Git VCS · Branching · Rebase Click any command to copy

Git Command
Reference

A complete annotated reference for everyday Git — from initialisation to rebase, cherry-pick, stash, and config. Click any command to copy it to clipboard. Use the search to filter across all commands.

70+
Commands covered
11
Command groups
3
Reset modes
Clipboard copies
🚀 Init & Clone
setup
git init
Initiates Git in the current directory — creates a .git hidden folder
init
git remote add origin https://github.com/repo_name.git
Add a remote repository called origin
remote
git clone <address>
Create a local copy of a remote repository
clone
git clone <address> -b <branch_name> <path/to/directory>
Clone into a specific directory and checkout the given branch
clone
git clone <address> -b <branch_name> --single-branch
Clone only a single branch — faster, smaller download
clone
📦 Staging & Reset
index
git add <file_name>
Stage a specific file for the next commit
stage
git add *
Stage all new modifications, deletions, and creations
stage
git reset file.txt
Unstage file.txt — removes it from the staging area, keeps working directory changes
reset
git reset --hard
Discard ALL uncommitted changes — resets staging area and working directory to HEAD. Destructive.
hard
git reset --soft <commit_id>
Move HEAD to commit_id — keeps staging area and working directory unchanged (1)
soft
git reset --mixed <commit_id>
Move HEAD + reset staging area, keep working directory (1)+(2) — default mode
mixed
git reset --hard <commit_id>
Move HEAD + reset staging area + reset working directory (1)+(2)+(3) — everything gone
hard
git rm file.txt
Remove file from both Git index and the file system
remove
git rm --cached file.txt
Remove file from Git index only — keeps it on disk (useful for files accidentally committed)
index
git status
Show modifications and files not yet staged
info
Reset modes — the 3 operations
--soft = move HEAD only  ·  --mixed = move HEAD + reset staging area (default)  ·  --hard = move HEAD + reset staging + reset working directory. Prefer git revert over reset in shared repositories — revert creates a new commit rather than rewriting history.
🌿 Branches
branching
git branch
List all local branches — current branch marked with a star
list
git branch -a
List all local and remote branches
list
git branch -vv
List all branches with their upstream and last commit on each
list
git branch my-branch
Create a new branch called my-branch
create
git branch -d my-branch
Delete my-branch locally (safe — won't delete if unmerged)
delete
git branch -m <new-branch-name>
Rename the current branch
rename
git checkout my-branch
Switch to my-branch
switch
git checkout --orphan <branch_name>
Create a branch with no commit history — a clean slate
switch
git merge my-branch
Merge my-branch into the current branch
merge
git push origin --delete my-branch
Delete remote branch my-branch on origin
delete
🍒 Cherry-pick
selective merge
git cherry-pick <commit_id>
Apply a specific commit onto the current branch
pick
git cherry-pick <commit_id_A>^..<commit_id_B>
Apply a range of commits from A to B — the ^ includes commit A itself
range
🌐 Remotes
remote
git remote
List all configured remotes
list
git remote -v
Show remote URLs for push and pull
list
git remote add my-remote <address>
Add a new remote named my-remote
add
git remote rm my-remote
Remove a remote
remove
git pull my-remote my-branch
Fetch and merge my-branch from remote — equivalent to git fetch + git merge
pull
git push my-remote my-branch
Push commits to my-remote/my-branch (does not push tags)
push
git fetch --tags
Pull all tags from remote without merging
fetch
🔍 Log & Diff
history
git log
Show commit history — uses less pager (f=next, b=prev, q=quit, /=search)
log
git log --oneline
Compact log — one commit per line
log
git log --oneline --graph --decorate
Compact log with ASCII branch graph — excellent for visualising branch structure
graph
git log --no-pager
Show log without the pager — outputs everything at once
log
git log --since=<time>
Show commits since a given time (e.g. 2.weeks, 2024-01-01)
filter
git log -p <file_name>
Show change history for a specific file — diffs included
filter
git log <Branch1> ^<Branch2>
Show commits in Branch1 that are NOT in Branch2
compare
git log -n <x> --oneline
Show the last x commits, one per line
log
git log --grep='<string/regex>'
Search commit messages by string or regex
search
git grep --heading --line-number '<string/regex>'
Search for a string/regex pattern inside tracked files — shows file and line number
search
git diff
Show unstaged changes between working directory and last commit
diff
git diff HEAD
Show all changes in working directory vs last commit (staged + unstaged)
diff
git diff --staged HEAD
Show staged changes vs last commit
diff
git diff --staged
Show only staged changes ready for commit
diff
git reflog
Show when branch tips and references were updated — a safety net for recovering lost commits
reflog
git ls-files
Show all tracked files in the index and working tree
info
git show
Show the most recent commit — blobs, trees, tags and commit objects
info
💾 Commit
snapshot
git commit -m "msg"
Commit staged changes with a message
commit
git commit -m "title" -m "description"
Commit with a title and a longer description body
commit
git commit --amend
Combine staged changes with the previous commit, or edit its message
amend
git commit --amend --no-edit
Amend the previous commit without changing its message
amend
git commit --amend --author='Name <email@address.com>'
Change the author of the previous commit
amend
git revert <commit-id>
Undo a commit by creating a new reverse commit — safe for shared repos, history preserved
revert
💡 Good commit message verbs
Use imperative mood — the first word should be: Add · Create · Refactor · Fix · Release · Document · Modify · Update · Remove · Delete. Keep messages short and specific. Think: "This commit will [your message]".
🏷 Tags
versioning
git tag
List all tags
list
git tag -a v1.0 -m "msg"
Create an annotated tag with a message
create
git show v1.0
Show the description and commit of tag v1.0
info
git tag --delete v1.0
Delete tag v1.0 locally
delete
git push --delete my-remote v1.0
Delete tag v1.0 on remote — careful not to accidentally delete a branch
delete
git push my-remote my-branch v1.0
Push tag v1.0 to remote
push
git fetch --tags
Pull all tags from remote
fetch
🗃 Stash
shelving
git stash
Shelve staged and unstaged changes — working directory becomes clean
stash
git stash -u
Stash everything including new untracked files (but not .gitignored files)
stash
git stash save "msg"
Stash with a descriptive label
stash
git stash list
List all stashes
list
git stash pop
Apply the most recent stash and delete it from the stash list
apply
git stash pop stash@{2}
Apply and delete a specific stash by index
apply
git stash apply
Apply the most recent stash but keep it in the stash list
apply
git stash show
Show a summary of the most recent stash
info
git stash branch my-branch stash@{1}
Create a new branch from a specific stash
branch
git stash drop stash@{1}
Delete a specific stash without applying it
delete
git stash clear
Delete ALL stashes — irreversible
delete
🔀 Rebase & Clean
history rewrite
git rebase -i <commit_id>
Interactive rebase from a commit — squash, reorder, edit, drop commits
rebase
git rebase --abort
Abort a running rebase and return to the original state
abort
git rebase --continue
Continue rebasing after resolving conflicts
continue
git clean -f
Permanently remove untracked files from working directory
clean
git clean -fd
Remove untracked files AND directories
clean
git clean -fX
Remove only files listed in .gitignore
clean
git clean -fx
Remove ignored AND non-ignored untracked files
clean
git clean -d --dry-run
Preview what would be deleted — without actually deleting anything
preview
git archive <branch_name> --format=zip --output=./<archive_name>.zip
Create a zip archive of a branch's contents
export
⚙️ Config
settings
git config --global --list
List all global Git configuration values
list
git config --global --edit
Open the global config file in the default editor
edit
git config --global alias.<handle> <command>
Create a Git alias — e.g. alias.st status lets you type git st
alias
git config --global core.editor <editor_name>
Set the default editor (e.g. vim, nano, code --wait)
editor

Key ideas worth remembering

~ vs ^ in commits
^ or ^n — navigate to the nth parent (useful after merges). ~ or ~n — go n commits back following the first parent. They can be combined: HEAD~2^2.
revert vs reset
Use git revert in shared repos — it adds a new commit that undoes the change, preserving history. Use git reset only on local/private branches — it rewrites history and will cause problems for teammates.
.gitignore
List file patterns you don't want tracked — local databases, media, .env files, build artefacts. .gitignore itself is tracked. The .git/ directory is hidden and never committed.
The staging area
Git has 3 areas: working directory, staging area (index), repository. git add moves to staging. git commit moves from staging to repo. This two-step model lets you craft precise commits.
Visualisation tools
Two excellent tools for learning Git visually: git-school.github.io/visualizing-git and learngitbranching.js.org. Both simulate git operations interactively in the browser.
reflog is your safety net
git reflog records every movement of HEAD — including reset, checkout, rebase. If you think you've lost commits, reflog shows the previous HEAD positions so you can recover them.
Git Command Reference · Complete annotated guide
Click any command to copy · Search across all commands
Git Branching Stash Rebase
Menu